package com.app.util.common;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/** 
 * 说明：日期处理
 */
public class DateUtil {
	
	private final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
	private final static SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");
	private final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
	private final static SimpleDateFormat sdfDays = new SimpleDateFormat("yyyyMMdd");
	private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	
	
	

	/**
	 * 获取YYYY格式
	 * @return
	 */
	public static String getYear() {
		return sdfYear.format(new Date());
	}
	
	/**
	 * 获取MM格式
	 */
	public static String getMonth() {
		return sdfMonth.format(new Date());
	}
	
	/**
	 * 获取YYYY-MM-DD格式
	 * @return
	 */
	public static String getDay() {
		return sdfDay.format(new Date());
	}
	
	/**
	 * 获取YYYYMMDD格式
	 * @return
	 */
	public static String getDays(){
		return sdfDays.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * @return
	 */
	public static String getTime() {
		return sdfTime.format(new Date());
	}
	/**
	 * 获取星期
	 * @param date
	 * @return
	 */
	public static int getWeek(Date date){
		Calendar cal=Calendar.getInstance();
		cal.setTime(date);
		return cal.getWeekYear();
	}

	/**
	* @Title: compareDate
	* @Description: TODO(日期比较，如果s>=e 返回true 否则返回false)
	* @param s
	* @param e
	* @return boolean  
	* @throws
	* @author fh
	 */
	public static boolean compareDate(String s, String e) {
		if(parseDate(s)==null||parseDate(e)==null){
			return false;
		}
		return parseDate(s).getTime() >=parseDate(e).getTime();
	}

	/**
	 * 格式化日期
	 * @return
	 */
	public static Date parseDate(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 格式化日期
	 * @return
	 */
	public static Date parseDate(String date, String dateType) {
		DateFormat fmt = new SimpleDateFormat(dateType);
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 格式化日志
	 * @param date 日期
	 * @param dateType 日期格式
	 * @return
	 */
	public static String fomatDate(Date date,String dateType) {
		if(date == null) {
			return "";
		}
		DateFormat fmt = new SimpleDateFormat(dateType);
		return fmt.format(date);
	}

	/**
	 * 校验日期是否合法
	 * @return
	 */
	public static boolean isValidDate(String s) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			fmt.parse(s);
			return true;
		} catch (Exception e) {
			// 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
			return false;
		}
	}
	
	/**
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static int getDiffYear(String startTime,String endTime) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			//long aa=0;
			int years=(int) (((fmt.parse(endTime).getTime()-fmt.parse(startTime).getTime())/ (1000 * 60 * 60 * 24))/365);
			return years;
		} catch (Exception e) {
			// 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
			return 0;
		}
	}
	 /**
     * 取得当前的时间，转化为java.sql.Date相符的字符传
     * @return  String
     */
    public static String getDateTime() {
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Date date = new java.util.Date();
        return simpledateformat.format(date);
    }
	/**
     * <li>功能描述：时间相减得到天数
     * @param beginDateStr
     * @param endDateStr
     * @return
     * long 
     * @author Administrator
     */
    public static long getDaySub(String beginDateStr,String endDateStr){
        long day=0;
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
        java.util.Date beginDate = null;
        java.util.Date endDate = null;
        
            try {
				beginDate = format.parse(beginDateStr);
				endDate= format.parse(endDateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
            day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
            //System.out.println("相隔的天数="+day);
      
        return day;
    }
    
    /**
     * 得到n天之后的日期
     * @param days
     * @return
     */
    public static String getAfterDayDate(String days) {
    	int daysInt = Integer.parseInt(days);
    	
        Calendar canlendar = Calendar.getInstance(); // java.util包
        canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
        Date date = canlendar.getTime();
        
        SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = sdfd.format(date);
        
        return dateStr;
    }
    
    /**
     * 得到n天之后是周几
     * @param days
     * @return
     */
    public static String getAfterDayWeek(String days) {
    	int daysInt = Integer.parseInt(days);
        Calendar canlendar = Calendar.getInstance(); // java.util包
        canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
        Date date = canlendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("E");
        String dateStr = sdf.format(date);
        return dateStr;
    }
    
    public static String getFormatDate(String str, String strType) {
        java.util.Date dtDate;
        if (str == null||str.equals("null")||str.equals(""))
            return "";
        if (str.indexOf(".") != -1)
            dtDate = new java.util.Date(str.substring(0, str.lastIndexOf(".")).replace('-', '/'));
        else
            dtDate = new java.util.Date(str.replace('-', '/'));
        String strValue = "";

        int iYear = dtDate.getYear() + 1900;
        int iMonth=dtDate.getMonth() + 1;
        String strMonth = (dtDate.getMonth() >= 9) ? ("" + (dtDate.getMonth() + 1)) : ("" + (dtDate.getMonth() + 1));
        if (Integer.valueOf(strMonth)<10)//小于10补“0”
        	strMonth = "0"+strMonth;
        String strDate = (dtDate.getDate() > 9) ? ("" + dtDate.getDate()) : ("" + dtDate.getDate());
        if (Integer.valueOf(strDate)<10)//小于10补“0”
        	strDate = "0"+strDate;
        if (strType.equals("yyyy/mm/dd")) {
            strValue = iYear + "/" + strMonth + "/" + strDate;
        }
        if (strType.equals("yyyy-mm-dd")) {
            strValue = iYear + "-" + strMonth + "-" + strDate;
        }
        if (strType.equals("yyyy-mm2-dd")) {
            strValue = iYear + "-" + iMonth + "-" + dtDate.getDate();
        }
        if (strType.equals("yyyy mm2 dd")) {
            strValue = iYear + "　" + iMonth + "　" + dtDate.getDate();
        }
        if (strType.equals("mm-dd")) {
           strValue = strMonth + "-" + strDate;
        }
        if (strType.equals("mm月dd日")) {
           strValue = strMonth + "月" + strDate+"日";
        }
        if (strType.equals("dd日")) {
           strValue = strDate+"日";
        }
        if (strType.equals("yyyy年mm月dd日")) {
            strValue = iYear + "年" + strMonth + "月" + strDate + "日";
        }
        if (strType.equals("yyyy年mm2月dd日")) {
            strValue = iYear + "年" + iMonth + "月" + dtDate.getDate() + "日";
        }
        if (strType.equals("yyyy/mm/dd hh:mm:ss")) {
            String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
            String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
            String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
            strValue = iYear + "/" + strMonth + "/" + strDate + " " + strHours + ":" + strMinutes + ":" + strSeconds;
        }
        if (strType.equals("yyyy-mm-dd hh:mm:ss")) {
            String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
            String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
            String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
            strValue = iYear + "-" + strMonth + "-" + strDate + " " + strHours + ":" + strMinutes + ":" + strSeconds;
        }

        if (strType.equals("yyyy-mm-dd hh:mm")) {
            String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
            String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
            String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
            strValue = iYear + "-" + strMonth + "-" + strDate + " " + strHours + ":" + strMinutes;
        }
        
        if (strType.equals("hh:mm")) {
            String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
            String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
            String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
            strValue = strHours + ":" + strMinutes;
        }

        if (strType.equals("yyyy年mm月dd日hh时mm分ss秒")) {
            String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
            String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
            String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
            strValue = iYear + "年" + strMonth + "月" + strDate + "日" + strHours + "时" + strMinutes + "分" + strSeconds + "秒";
        }

        if (strType.equals("yyyy年mm月dd日hh时mm分")) {
            String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
            String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
            String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
            strValue = iYear + "年" + strMonth + "月" + strDate + "日" + strHours + "时" + strMinutes + "分";
        }
        if (strType.equals("yyyy_mm_dd")) {
             strValue = Tools.convertToChineseNumber(iYear) + "年" + Tools.convertToChineseDate(iMonth) + "月" + Tools.convertToChineseDate(dtDate.getDate()) + "日" ;
        }
        return strValue;
    }
    
    public static java.util.Date strToDate(String strDate, SimpleDateFormat sf) {
        try {
            return new java.util.Date((sf.parse(strDate).getTime()));
        } catch (Exception e) {
            return null;
        }
    }
    
    public static String get(java.util.Date dtDate, String strType) {

        if (null == dtDate) return "";

        int iYear = dtDate.getYear() + 1900;
        String sMonth = (dtDate.getMonth() >= 9) ? ("" + (dtDate.getMonth() + 1)) : ("" + (dtDate.getMonth() + 1));
        String sDate = (dtDate.getDate() > 9) ? ("" + dtDate.getDate()) : ("" + dtDate.getDate());
        if (Integer.valueOf(sMonth)<10)//小于10补“0”
        	sMonth = "0"+sMonth;
        if (Integer.valueOf(sDate)<10)//小于10补“0”
        	sDate = "0"+sDate;
        String strValue = "";
        try {
            if (strType.equals("yyyy/mm/dd")) {
                strValue = iYear + "/" + sMonth + "/" + sDate;
            }
            if (strType.equals("yyyy/mm")) {
                strValue = iYear + "/" + sMonth;
            }
            if (strType.equals("yyyy-mm-dd")) {
                strValue = iYear + "-" + sMonth + "-" + sDate;
            }
            if (strType.equals("mm-dd")) {
                strValue = sMonth + "-" + sDate;
            }
            if (strType.equals("mm月dd日")) {
                strValue = sMonth + "月" + sDate + "日";
            }
            if (strType.equals("yyyy年mm月dd日")) {
                strValue = iYear + "年" + sMonth + "月" + sDate + "日";
            }
            if (strType.equals("hh:mm:ss")) {
            	String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
                String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
                String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
                strValue =strHours + ":" + strMinutes + ":" + strSeconds;
            }
            if (strType.equals("yyyy/mm/dd hh:mm:ss")) {
                String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
                String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
                String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
                strValue = iYear + "/" + sMonth + "/" + sDate + " " + strHours + ":" + strMinutes + ":" + strSeconds;
            }

            if (strType.equals("yyyy年mm月dd日hh时mm分ss秒")) {
                String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
                String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
                String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
                strValue = iYear + "年" + sMonth + "月" + sDate + "日" + strHours + "时" + strMinutes + "分" + strSeconds + "秒";
            }

            if (strType.equals("yyyy年mm月dd日hh时mm分")) {
                String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
                String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
                String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
                strValue = iYear + "年" + sMonth + "月" + sDate + "日" + strHours + "时" + strMinutes + "分";
            }
            if (strType.equals("yyyy年mm月dd日  hh:mm")) {
                String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
                String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
                String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
                strValue = iYear + "年" + sMonth + "月" + sDate + "日  " + strHours + ":" + strMinutes;
            }
            if (strType.equals("yyyy-mm-dd hh:mm:ss")) {
                String strHours = (dtDate.getHours() > 9) ? ("" + dtDate.getHours()) : ("0" + dtDate.getHours());
                String strMinutes = (dtDate.getMinutes() > 9) ? ("" + dtDate.getMinutes()) : ("0" + dtDate.getMinutes());
                String strSeconds = (dtDate.getSeconds() > 9) ? ("" + dtDate.getSeconds()) : ("0" + dtDate.getSeconds());
                strValue = iYear + "-" + sMonth + "-" + sDate + " " + strHours + ":" + strMinutes + ":" + strSeconds;
            }
        } catch (Exception e) {
        	e.printStackTrace();
            strValue = "";
        }
        return strValue;
    }
    
    
    
    
    /**
    * <p>Title: 周计算类，星期一为一周的开始，星期日为一周的结束</p> 
    * <p>Description: 在两年的交接地带还有疑问。</p>
    *
    * @version 1.0
    */
   
    /**
    * 取得当前日期是多少周
    * 
    * @param date
    * @return
    */
    public static int getWeekOfYear(Date date) {
	    Calendar c = new GregorianCalendar();
	    c.setFirstDayOfWeek(Calendar.MONDAY);
//	    c.setMinimalDaysInFirstWeek(7);
	    c.setTime (date);
	
	    return c.get(Calendar.WEEK_OF_YEAR);
    }

    /**
    * 得到某一年周的总数
    * 
    * @param year
    * @return
    */
    public static int getMaxWeekNumOfYear(int year) { 
    	Calendar c = new GregorianCalendar();
        c.set(year, Calendar.DECEMBER, 31, 23, 59, 59);        
        return 53 ;
    }

    /**
    * 得到某年某周的第一天
    * 
    * @param year 
    * @param week
    * @return
    */
    public static Date getFirstDayOfWeek(int year, int week) {
    	
    	week = week -1 ;
    	Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.YEAR, year);
    	calendar.set (Calendar.MONTH, Calendar.JANUARY);
    	calendar.set(Calendar.DATE, 1);
    	//calendar.setMinimalDaysInFirstWeek(4);
    	Calendar cal = (Calendar)calendar.clone();
    	cal.add(Calendar.DATE, week*7);
    	return getFirstDayOfWeek(cal.getTime());
    }

    /**
    * 得到某年某周的最后一天
    * 
    * @param year
    * @param week
    * @return
    */
    public static Date getLastDayOfWeek(int year, int week) {
    	week = week -1;
    	Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.YEAR, year);
    	calendar.set (Calendar.MONTH, Calendar.JANUARY);
    	calendar.set(Calendar.DATE, 1);
    	//calendar.setMinimalDaysInFirstWeek(4);
    	Calendar cal = (Calendar)calendar.clone();
    	cal.add(Calendar.DATE, week*7);
    	return getLastDayOfWeek(cal.getTime());
    }

    /**
    * 取得当前日期所在周的第一天
    * 
    * @param date
    * @return
    */
    public static Date getFirstDayOfWeek(Date date) { 
	    Calendar c = new GregorianCalendar();
	    c.setFirstDayOfWeek(Calendar.MONDAY);
	    c.setTime(date);
	    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday
	    return c.getTime ();
    }
    
    public static String getWeekOfDate(Date dt) {
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }

    /**
    * 取得当前日期所在周的最后一天
    * 
    * @param date
    * @return
    */
    public static Date getLastDayOfWeek(Date date) {
    Calendar c = new GregorianCalendar();
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setTime(date);
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday
    return c.getTime();
    }

    public static void main(String[] args) { 
	    
    	Date date = getFirstDayOfWeek(new Date());
    	
    	System.out.println("-----"+getAfterDate(date, 3, "1"));
    	System.out.println("----"+getAfterDate("2018-12-01", 2, "1"));
    }
    
    /**
     * 根据条件获取以后的时间
     * @param beginDate 当前时间
     * @param delayDate 延期天数 
     * @param type 类型(1、天2、月)
     * @return
     */
    public static Date getAfterDate(String beginDate,int delayDate,String type){
    	Date afterMonthDate=null;
    	try {
            Date dtNowDate=parseDate(beginDate);
            Calendar rightNow = Calendar.getInstance();
            rightNow.setTime(dtNowDate);
            if(("1").equals(type)){
                rightNow.add(Calendar.DAY_OF_YEAR,delayDate);//天相加
            }else if(("2").equals(type)){
                rightNow.add(Calendar.MONTH,delayDate);//月份相加
            }
            afterMonthDate=rightNow.getTime();
		} catch (Exception e) {
			e.printStackTrace();
		}
    	return afterMonthDate;
    }
    
    
    /**
     * 根据条件获取以后的时间
     * @param strNowDate 当前时间
     * @param beginDate 延期天数
     * @param type 类型(1、天2、月)
     * @return
     */
    public static Date getAfterDate(Date beginDate,int delayDate,String type){
    	Date afterMonthDate=null;
    	try {
            Calendar rightNow = Calendar.getInstance();
            rightNow.setTime(beginDate);
            if(("1").equals(type)){
                rightNow.add(Calendar.DAY_OF_YEAR,delayDate);//天相加
            }else if(("2").equals(type)){
                rightNow.add(Calendar.MONTH,delayDate);//月份相加
            }
            afterMonthDate=rightNow.getTime();
		} catch (Exception e) {
			e.printStackTrace();
		}
    	return afterMonthDate;
    }
    
    /**
	 * 日期比较相差天数
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	public static Long diffDay(String beginDate,String endDate){
		Long diffDay = 0L;
		
		try{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			if(beginDate == null || beginDate.equals("")){
				beginDate = sdf.format(new Date());
			}
			if(endDate == null || endDate.equals("")){
				endDate = sdf.format(new Date());
			}
			
	        Date fDate = sdf.parse(beginDate);
	        Date oDate = sdf.parse(endDate);
	        diffDay = (oDate.getTime()-fDate.getTime())/(1000*3600*24);
	       
		}catch(Exception e){
			e.printStackTrace();
		}
		return diffDay;
	}
	
	/**
     *  计算当月的天数
     * @param YYMM 20099
     * @return 天数
     * @throws ParseException
     */
    public static int dateNums(String YYMM) throws ParseException{   
	   String strDate = YYMM;
	   SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
	   Calendar calendar = new GregorianCalendar();
	   Date date = sdf.parse(strDate);
	   calendar.setTime(date);
	   int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
	   return day;
    }
    
    /**
	 * 取得当前的时间，转化为java.sql.Date相符的字符传
	 * @return  String
	 */
	public static java.sql.Timestamp getTimestamp() {
		java.util.Date date = new java.util.Date();
		return new java.sql.Timestamp(date.getTime());
	}

	/**
	 * 根据年份，月份获取当前月最后一天
	 * @param tYear
	 * @param tMonth
	 * @return
	 */
	public static int getFinishOfDay(int tYear,int tMonth){
		int intDay=30;
		if(tMonth==1 || tMonth==3 || tMonth==5 || tMonth==7 || tMonth==8 || tMonth==10 || tMonth==12){
			intDay=31;
		}else if(tMonth==2){
			 if(tYear%400==0||(tYear%4==0&&tYear%100!=0)){
				 intDay=29;
	         }else{
	        	 intDay=28;
	         }
		}else{
			intDay=30;
		}
		
		return intDay;
	}
}
